#ifndef __MYTASK_H__
#define __MYTASK_H__

#include "TcpConnection.h"
#include "Cache.h"
#include <string>
#include <set>
#include <queue>
#include <vector> 

using std::string;
using std::set;
using std::priority_queue;
using std::vector;

struct MyResult
{
    string _word;
    int _iFreq;
    int _iDist;
    MyResult(const string word,int iFreq,int iDist)
        :_word(word)
         ,_iFreq(iFreq)
         ,_iDist(iDist)
    {}
};
struct Mycompare
{
    bool operator()(MyResult a,MyResult b){
        if(a._iDist==b._iDist) return a._iFreq<b._iFreq;
        //编辑距离相同，词频大的优先
        return a._iDist>b._iDist;
        //编辑距离小的优先
    }
};

class MyTask
{
public:
    MyTask(const string& queryWord,const xkk::TcpConnectionPtr &conn);
    void execute();
    void queryIndexTable();
    void statistic(set<int>&iset);
    int distance(const string &rhs);
    void response(Cache& cache);
private:
    string getFirstWord();
    int getUtf8CharLength(char c);
private:
    string _queryWord;
    xkk::TcpConnectionPtr _conn;
    priority_queue<MyResult,vector<MyResult>,Mycompare> _resultQue;

};

#endif
